import talib
import pandas as pd
import numpy as np

# 假设我们有一段时间的价格和成交量数据
data = {
    "close": [100, 102, 105, 103, 101, 102, 104, 103, 102],
    "volume": [1000, 1200, 1500, 1000, 800, 900, 1100, 900, 850],
}
df = pd.DataFrame(data)

# 计算移动平均线和成交量的变化
df["ma_5"] = talib.SMA(df["close"], timeperiod=5)
df["volume_diff"] = df["volume"].diff()

print(df["ma_5"])
print(df["volume_diff"])

# 识别缩量回调
for index, row in df.iterrows():
    if index > 4:  # 确保有足够的数据计算移动平均线
        if row["close"] < row["ma_5"] and row["volume_diff"] < 0:
            print(f"At index {index}, possible缩量回调.")
